package com.dr.dac.knowledgebase.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 创建便签的数据库
 *
 *数据库
 */
public class DatabaseHelper extends SQLiteOpenHelper {

    public static final String ELXC_DATABASE_NAME = "K_DB";

    /*
     * K_Class
     */
    public static final String TABLE_NAME_K_CATEGORY = "K_Category";

    /*
     * K_FunctionPoint
     */
    public static final String TABLE_NAME_K_FunctionPoint = "K_FunctionPoint";

    /*
     * K_Content
     */
    public static final String TABLE_NAME_K_Content = "K_Content";


    //--------创建K_Class表格----------
    public static final String CREATE_TABLE_K_Category= "create table if not exists "
            + TABLE_NAME_K_CATEGORY + "(" + "ClassMID varchar(20),ClassSID varchar(30)," +
            "CategoryName varchar(20),AttributeName varchar(30),FPointID varchar(20)," +
            "FPointIDName varchar(20),HandleID varchar(30),KeyWord varchar(1000) "+
            ",PRIMARY KEY(ClassMID)"+")";

    //--------创建K_FunctionPoint表格----------
    public static final String CREATE_TABLE_K_FunctionPoint = "create table if not exists "
            + TABLE_NAME_K_FunctionPoint + "(" + "FPointID varchar(20),ClassSID varchar(30)," +
            "FPointIDName varchar(20),HandleID varchar(30),KeyWord varchar(1000) " +
            ",PRIMARY KEY(FPointID)"+")";

    //--------创建K_Content表格----------
    public static final String CREATE_TABLE_K_Content = "create table if not exists "
            + TABLE_NAME_K_Content + "(" + "ContentID varchar(20),FPointID varchar(30),ClassMID varchar(30)," +
            "ContentName varchar(20),Author varchar(30),Content varchar(1000),PublishTime varchar(30)," +
            "Field varchar(30),Source varchar(30),KeyWord varchar(1000) "+
            ",PRIMARY KEY(ContentID)"+")";

    private static DatabaseHelper instance = null;

    public DatabaseHelper(Context context) {
        super(context, ELXC_DATABASE_NAME, null, 1);


    }
    public static DatabaseHelper getInstance(Context context) {
        if (instance == null) {
            instance = new DatabaseHelper(context);
        }
        return instance;
    }


    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL(CREATE_TABLE_K_Category);
        db.execSQL(CREATE_TABLE_K_FunctionPoint);
        db.execSQL(CREATE_TABLE_K_Content);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

}